<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        let data={
            name:'zt',
            address:'东三旗'
        }
        //创建一个监视的实例对象，用于监视data中属性的变化
        const obs=new Observer(data)
        data=obs
        function Observer(obj){
            const keys=Object.keys(obj)

            keys.forEach(k=>{
                //定义key 和对应的getter setter
                Object.defineProperty(this,k,{
                    get(){
                        return obj[k]
                    },
                    set(val){
                        console.log(`${k}被修改了,我要去解析模板，生成虚拟dom......我要开始忙了。`)
                        obj[k]=val
                    } 
                })
            })
        }

    </script>
</body>
</html>